package com.example.easybuy.exception;

import com.example.easybuy.util.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);

    @ExceptionHandler({NameAndPasswordException.class})
    public AjaxResult nameAndPasswordExceptionHandler(NameAndPasswordException e) {
        logger.debug("异常信息：" + e.getMessage());
        return AjaxResult.error(5002, e.getMessage());
    }

    @ExceptionHandler({NoLoginException.class})
    public AjaxResult noLoginExceptionHandler(NoLoginException e) {
        logger.debug("异常信息：" + e.getMessage());
        return AjaxResult.error(5003, e.getMessage());
    }

    @ExceptionHandler({LoginTimeOutException.class})
    public AjaxResult LoginTimeOutExceptionHandler(LoginTimeOutException e) {
        logger.debug("异常信息：" + e.getMessage());
        return AjaxResult.error(5004, e.getMessage());
    }
    @ExceptionHandler({CheckTokenException.class})
    public AjaxResult CheckTokenExceptionHandler(CheckTokenException e) {
        logger.debug("异常信息：" + e.getMessage());
        return AjaxResult.error(5005, e.getMessage());
    }
    @ExceptionHandler({PermissionException.class})
    public AjaxResult permissionExceptionExceptionHandler(PermissionException e) {
        logger.debug("异常信息：" + e.getMessage());
        return AjaxResult.error(5006, e.getMessage());
    }

//    @ExceptionHandler({Exception.class})
//    public AjaxResult exceptionHandler(Exception e) {
//        logger.debug("异常信息：" + e.getMessage());
//        return AjaxResult.error(5001, e.getMessage());
//    }

}